package net.arvin.dao;

import java.util.List;
import java.util.Map;

import net.arvin.mobilebanksystem.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter {

	private List<Map<String, Object>> lists;
	private Context mContext;
	private LayoutInflater inflater;

	public GridViewAdapter(Context context, List<Map<String, Object>> views) {
		this.mContext = context;
		inflater = LayoutInflater.from(mContext);
		this.lists = views;

	}

	@Override
	public int getCount() {
		if (this.lists == null) {
			return 0;
		}
		return this.lists.size();
	}

	@Override
	public Object getItem(int position) {
		return this.lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.gridview_item, null);
			viewHolder = new ViewHolder();
			viewHolder.title = (TextView) convertView.findViewById(R.id.title);
			viewHolder.image = (ImageView) convertView.findViewById(R.id.img);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.title.setText((String) lists.get(position).get("title"));
		viewHolder.image.setImageResource((Integer) lists.get(position).get(
				"img"));
		return convertView;
	}

	private class ViewHolder {
		public TextView title;
		public ImageView image;
	}
}